const HtmlWebpackPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin  = require('copy-webpack-plugin')
const { DefinePlugin } = require('webpack')
const pk = require('./package.json')

module.exports = {
  mode: 'production',
  entry: './html/index.ts',
  output: {
    clean: true,
    filename: 'js/[name].[fullhash:8].js',
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: pk.name,
      template: './index.ejs'
    }),
    new CopyWebpackPlugin({
      patterns: [
        { from: "html/theme.css", to: "./theme.css" },
        { from: "html/example", to: "./example" },
        { from: "html/document", to: "./document" },
        { from: "html/background", to: "./background" }
      ]
    }),
    new DefinePlugin({
      API_VERSION: JSON.stringify(require('./package.json').version)
    })
  ],
  resolve: {
    extensions: ['.ts', '.js', '.tsx', 'json']
  },
  optimization: {
    minimize: false
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        exclude: /node_modules/,
        use: [{ loader: 'ts-loader' }]
      },
      {
        test: /\.html$/,
        use: 'raw-loader'
      }
    ]
  }
}